﻿using Microsoft.EntityFrameworkCore;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Domain.Repository;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.Repository
{
    public class MaterialRepository : RepositoryBase, IMaterialRepository
    {
        public MaterialRepository(WmsDbContext dbContext) : base(dbContext)
        {
        }

        public async Task<MaterialPO?> GetMaterialByBindCode(List<string> materialTypeCodeList, string bindBarcode)
        {
            return await dbContext.Set<MaterialPO>().AsNoTrackingWithIdentityResolution().FirstOrDefaultAsync(entity => materialTypeCodeList.Contains(entity.TypeCode) && entity.BindBarcode == bindBarcode);
        }

        public async Task<MaterialPO?> GetMaterialByCode(string materialCode)
        {
            return await dbContext.Set<MaterialPO>().AsNoTrackingWithIdentityResolution().FirstOrDefaultAsync(entity => entity.Code == materialCode);
        }
    }
}
